<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="f"%>

	<table class = "table">
		<tr>
			<td>编号</td>
			<td>用户名</td>
			<td>注册时间</td>
			<td>状态</td>
			<td>角色</td>
			<td>操作</td>
		</tr>
		<!-- id,username ,password,nickname,birthday,gender,locked,create_time,update_time,url,score,role -->
		<c:forEach items="${userPage.list }" var="l">
			<tr>
				<td>${l.id }</td>
				<td>${l.username }</td>
				<td>
					<fmt:formatDate value="${l.create_time }" pattern="yyyy-MM-dd"/>
				</td>
				<td>${l.locked==1?'禁用':'活动' }</td>
				<td>${l.role==1?'管理':'用户' }</td>
				<td>
					<c:choose>
						<c:when test="${l.locked==1 }">
							<button type="button" class="btn btn-primary" onclick = "changeStatus(${l.id},0)">解禁</button>
						</c:when>
						<c:when test="${l.locked==0 }">
							<button type="button" class="btn btn-danger" onclick = "changeStatus(${l.id},1)">禁用</button>
						</c:when>
					</c:choose>
				
				</td>			
			</tr>
		</c:forEach>
	</table>
	
	<nav aria-label="Page navigation example">
	  <ul class="pagination justify-content-end">
		    <li class="page-item">
		      <a class="page-link" onclick = "page(1)" href="#" tabindex="-1" aria-disabled="flase">首页</a>
		    </li>
		    
		    <c:forEach begin="${userPage.pageNum-2 > 1?userPage.pageNum:1 }" 
		    	end="${userPage.pageNum+2<userPage.pages?userPage.pageNum+2:userPage.pages }" step="1" var="page">
		    	
			    <li class="page-item">
			   	 	<a class="page-link" href="#" onclick = "page(${page})">${page }</a>
			    </li> 
		    </c:forEach>
		    
		    <li class="page-item">
		      <a class="page-link" href="#" onclick = "page(${userPage.pages})">尾页</a>
		    </li>
	  </ul>
	</nav>
	<script type="text/javascript">
	
		function page(pageNum){
			
			alert(pageNum);
			$("#workContent").load("/show/findUser?pageNum="+pageNum);
			
		}
		
		function changeStatus(userId,num){
			
			alert("!");
			
			console.log(userId+"--"+num);
			
			if(confirm("确定修改吗？")){
				$.post("/show/changeStatus",{uid:userId,flag:num},function(msg){
					if(msg>0){ 
						alert("修改成功!");
						$("#workContent").load("/show/findUser?pageNum="+${userPage.pageNum});	
					}	
				})
			}	
		}
	
	
		
	/* 	$.post("/show/changeStatus",{uid:userId,flag:num}),function(msg){
			
			if(msg > 0){
				alert("操作成功!");
				
			}
			
		}) */
	
	
	</script>	
	
	

